﻿/*
Copyright 2009 Matías Fidemraizer (www.matiasfidemraizer.com).

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

using System;
using System.Linq;
using System.Collections.Generic;

namespace Comkarl.Architecture.Patterns
{
    /// <summary>
    /// Represents a manager of pattern instances which is an organizative-like entity.
    /// </summary>
    /// <typeparam name="TInstance">
    /// The type for the instances.
    /// </typeparam>
    /// <typeparam name="TIdentifierName">
    /// The type for the identifier's name
    /// </typeparam>
    public abstract class PatternInstanceManager<TInstance, TIdentifierName> : List<TInstance> where TIdentifierName : IEquatable<TIdentifierName> where TInstance : PatternInstance<TIdentifierName>
    {
        /// <summary>
        /// Hides the default indexer.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        new private TInstance this[int index] { get { return null; } }

        #region Properties
        /// <summary>
        /// Provides identifier-by-based access to the living pattern instances.
        /// </summary>
        /// <param name="id">
        /// A valid identifier for an living pattern instance.
        /// </param>
        /// <returns>
        /// The pattern instance for the provided instance.
        /// </returns>
        public TInstance this[PatternInstanceIdentifier<TIdentifierName> id]
        {
            get
            {
                return (from TInstance someInstance in this where someInstance.ID == id select someInstance).First<TInstance>();
            }
        }
        #endregion
    }
}
